package random.fox.p2p.ui;

import android.content.Context;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

import javax.inject.Inject;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;
import flow.Flow;
import random.fox.p2p.App;
import random.fox.p2p.Paths;
import random.fox.p2p.R;
import random.fox.p2p.event.ActionBarEvent;
import random.fox.p2p.event.ProgressEvent;
import random.fox.p2p.model.IndexModule;
import random.fox.p2p.model.ReplyModule;
import random.fox.p2p.presenter.ReplyPresenter;
import random.fox.p2p.view.IReplyVierw;

/**
 * 评论界面
 * Created by wq on 15/3/19.
 */
public class ReplyView extends LinearLayout implements IReplyVierw {

    @Inject
    ReplyPresenter presenter;
    @InjectView(R.id.toolbar)
    Toolbar toolbar;
    @InjectView(R.id.edt_reply)
    EditText editText;
    @InjectView(R.id.btn_reply)
    Button button;

    public ReplyView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ButterKnife.inject(this);
        ((App) getContext().getApplicationContext()).createScopedGraph(new ReplyModule(this)).inject(this);
        toolbar.setTitle("评论");
        EventBus.getDefault().post(new ActionBarEvent(toolbar, -1, true));
    }

    @OnClick(R.id.btn_reply) void btnOnClicked(){
        Paths.ReplyPath replyPath = (Paths.ReplyPath) Flow.get(getContext()).getBackstack().current();
        int mid = replyPath.index;
        String str =editText.getText().toString();
        presenter.addReply(mid , str);
    }

    @Override
    public void showProgress() {
        EventBus.getDefault().post(new ProgressEvent(true));
    }

    @Override
    public void hideProgress() {
        EventBus.getDefault().post(new ProgressEvent(false));
    }

    @Override
    public void showMessage(String message) {
        Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void goBack() {
        Flow.get(getContext()).goBack();
    }
}
